package mailcommon.entities;

import java.io.Serializable;
import java.util.Date;
import mailcommon.helpers.DateHelper;

public class User implements Serializable {

    private String lastname;
    private String firstname;
    private Date birthdate;
    private String telephone;
    private int id;

    public User() {
    }

    /**
     * Constructor for newly created User object.
     *
     * @param lastname
     * @param firstname
     * @param birthdate
     * @param telephone
     */
    public User(String lastname, String firstname, Date birthdate, String telephone) {
        this.lastname = lastname;
        this.firstname = firstname;
        this.birthdate = birthdate;
        this.telephone = telephone;
    }

    /**
     * Constructor for newly created User object.
     *
     * @param lastname
     * @param firstname
     * @param birthdate expected string representation of date in format
     * "yyyy-MM-dd"
     * @param telephone
     */
    public User(String lastname, String firstname, String birthdate, String telephone) {
        this(lastname, firstname, DateHelper.getInstance().parse(birthdate), telephone);
    }

    /**
     * Constructor for User object readed from DB wich had id.
     *
     * @param lastname
     * @param firstname
     * @param birthdate
     * @param telephone
     * @param id
     */
    public User(String lastname, String firstname, Date birthdate, String telephone, int id) {
        this.lastname = lastname;
        this.firstname = firstname;
        this.birthdate = birthdate;
        this.telephone = telephone;
        this.id = id;
    }

    /**
     * Constructor for User object readed from DB wich had id.
     *
     * @param lastname
     * @param firstname
     * @param birthdate expected string representation of date in format
     * "yyyy-MM-dd"
     * @param telephone
     * @param id
     */
    public User(String lastname, String firstname, String birthdate, String telephone, int id) {
        this(lastname, firstname, DateHelper.getInstance().parse(birthdate), telephone, id);
    }

    @Override
    public String toString() {
        return lastname
                + " " + firstname
                + " " + DateHelper.getInstance().format(birthdate)
                + " " + telephone;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public Date getBirthdate() {
        return birthdate;
    }

    public String getBirthdateString() {
        return DateHelper.getInstance().format(birthdate);
    }

    public void setBirthdate(Date birthdate) {
        this.birthdate = birthdate;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public int getId() {
        return id;
    }
}
